package com.example.final_project.Usr.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.final_project.Comm.entry.CommContent;
import com.example.final_project.R;

import java.util.List;

public class WorkAdapter extends RecyclerView.Adapter {

    private List<CommContent> commContents;
    private Context context;

    public WorkAdapter(List<CommContent> list, Context context){
        this.commContents = list;
        this.context = context;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

        RecyclerView.ViewHolder holder = null;
        View view = LayoutInflater.from(context).inflate(R.layout.user_author_work_tag,parent,false);
        holder = new CommHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        CommHolder commHolder = (CommHolder) holder;
        commHolder.setComm(position);
    }

    @Override
    public int getItemCount() {
        return commContents.size();
    }

    class CommHolder extends RecyclerView.ViewHolder {
        public CommHolder(@NonNull View itemView) {
            super(itemView);
        }

        public void setComm(int position){
            CommContent content = commContents.get(position);
            TextView name = itemView.findViewById(R.id.user_author_work_tag_name);
            TextView comm = itemView.findViewById(R.id.user_author_work_tag_comm);
            name.setText(content.getName());
            comm.setText(content.getContent());
        }

    }

}
